<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://graphml.graphdrawing.org/xmlns" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd" xmlns:fn="http://www.w3.org/2005/xpath-functions" 
>

<xsl:key name="module" match="SystemCModel/ModuleList//Module" use="@id" />
<xsl:key name="port" match="SystemCModel/ModuleList//Port" use="@name" />

	<xsl:output  method="xml" indent="yes"/> 
	<xsl:template match="SystemCModel">
		<graphml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
			<key id="d0" for="node" attr.name="description" attr.type="string" />
			<key for="edge" id="d6" yfiles.type="edgegraphics"/>
			<key for="node" id="d3" yfiles.type="nodegraphics"/>
			<graph id="g0" edgedefault="directed">		
				<xsl:apply-templates select="ModuleList"/>
				<xsl:apply-templates select="ChannelList"/>
			</graph>	
		</graphml>
	</xsl:template>
	
	<xsl:template match="Module">
		<xsl:for-each select=".">
		<node id="{generate-id()}">
		<data key="d0"><xsl:value-of select="@name"/></data>
      <data key="d3">
        <y:ProxyAutoBoundsNode>
          <y:Realizers active="0">
            <y:GroupNode>
              <y:Fill color="#FFCC99" transparent="false"/>
              <y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#FF6500" borderDistance="0.0" fontFamily="Dialog" fontSize="16" fontStyle="plain" hasLineColor="false" height="23.6015625" modelName="internal" modelPosition="t" textColor="#FFFFFF" visible="true" width="90.0" x="0.0" y="0.0"><xsl:value-of select="@name"/></y:NodeLabel>
              <y:State closed="false" innerGraphDisplayEnabled="false"/>			  
            </y:GroupNode>
            <y:GroupNode>		
              <y:Fill color="#FFCC99" transparent="false"/>
              <y:NodeLabel alignment="right" autoSizePolicy="node_width" backgroundColor="#FF6500" borderDistance="0.0" fontFamily="Dialog" fontSize="16" fontStyle="plain" hasLineColor="false" height="23.6015625" modelName="internal" modelPosition="t" textColor="#FFFFFF" visible="true" width="90.0" x="0.0" y="0.0"><xsl:value-of select="@name"/></y:NodeLabel>
              <y:State closed="false" innerGraphDisplayEnabled="false"/>
            </y:GroupNode>
          </y:Realizers>
        </y:ProxyAutoBoundsNode>
      </data>
			<graph id="{generate-id(@name)}" edgedefault="directed">	
				<xsl:apply-templates  select="Module"/>
				<xsl:for-each select="Process">
					<node id="{generate-id()}">
						<data key="d0"><xsl:value-of select="@name"/> :<xsl:value-of select="@type"/></data>
						<data key="d3">
							<y:ShapeNode>
							  <y:Geometry width="{string-length(string-join((@name,@type),' :'))*8}"/>
							  <xsl:if test="@type='method'">
							  	  <y:Fill color="#00CC00" transparent="false"/>
							  </xsl:if>
							  <xsl:if test="@type='thread'">
							  	  <y:Fill color="#00BBDD" transparent="false"/>
							  </xsl:if>
				
							  <y:BorderStyle color="#000000" type="line" width="1.0"/>
							  <y:NodeLabel alignment="center" fontFamily="Courier New" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="internal" modelPosition="c" textColor="#000000" visible="true" width="29.9"><xsl:value-of select="@name"/> :<xsl:value-of select="@type"/></y:NodeLabel>
							  <y:Shape type="rectangle"/>
							</y:ShapeNode>
						</data>
					</node>
				</xsl:for-each>
			</graph>
		</node>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="Channel">
		<xsl:for-each select=".">
			<edge id="{generate-id()}" source="{generate-id(key('module', @sourceModule))}" target="{generate-id(key('module', @targetModule))}">
			<data key="d6">
				<y:PolyLineEdge>
					<xsl:if test="@bidirectional='false'">
						<y:Arrows source="none" target="standard"/>
						<y:EdgeLabel alignment="center" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="six_pos" modelPosition="thead" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" visible="true"><xsl:value-of select="@targetPort"/> :<xsl:value-of select="key('port',@targetPort)/@type" /></y:EdgeLabel>
						<y:EdgeLabel alignment="center" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="six_pos" modelPosition="shead" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" visible="true"><xsl:value-of select="@sourcePort"/> :<xsl:value-of select="key('port',@sourcePort)/@type" /></y:EdgeLabel>
					</xsl:if>
					<xsl:if test="@bidirectional='true'">
						<y:Arrows source="standard" target="standard"/>
						<y:EdgeLabel alignment="center" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="six_pos" modelPosition="thead" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" visible="true"><xsl:value-of select="@targetPort"/> :<xsl:value-of select="key('port',@targetPort)/@type" /></y:EdgeLabel>
						<y:EdgeLabel alignment="center" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" modelName="six_pos" modelPosition="shead" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" visible="true"><xsl:value-of select="@sourcePort"/> :<xsl:value-of select="key('port',@sourcePort)/@type" /></y:EdgeLabel>
					</xsl:if>
				</y:PolyLineEdge>
			</data>

			
				
			</edge>
		</xsl:for-each>

	</xsl:template>


</xsl:stylesheet>


